<template>
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      label-width="68px"
    >
      <el-row :gutter="10">
        <!-- <el-col :span="4">
          <el-form-item label="商品类别" prop="commodityType">
            <el-cascader
              ref="commodityType"
              v-model="commodityType"
              :options="options"
              :props="props"
              clearable
            ></el-cascader>
          </el-form-item>
        </el-col> -->
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select
              v-model="queryParams.projectRegion"
              placeholder="请选择"
              clearable
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="dict in dict.type.cld_project_region"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="姓名" prop="staffName">
            <el-input
              v-model="queryParams.staffName"
              placeholder="请输入"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="时间区域">
            <el-date-picker
              v-model="dateRange"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
        <el-form-item label-width="10px">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column
        label="商品类别"
        align="center"
        prop="commodityTypeName"
      />
      <el-table-column label="仓库名称" align="center" prop="wareName" />
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.cld_project_region"
            :value="scope.row.projectRegion"
          />
        </template>
      </el-table-column>
      <el-table-column label="项目业态" align="center" prop="projectBusiness">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.cld_project_business"
            :value="scope.row.projectBusiness"
          />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="职务" align="center" prop="projectDuitsName">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.cld_project_duits"
            :value="scope.row.projectDuitsName"
          />
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="staffName" />
      <el-table-column label="商品名称" align="center" prop="commodityName" />
      <el-table-column label="规格" align="center" prop="commoditySpec" />
      <el-table-column label="单位" align="center" prop="unitName1" />
      <el-table-column label="辅助单位" align="center" prop="unitName2" />
      <!--<el-table-column label="供应商" align="center" prop="companyName" />-->
      <el-table-column label="成本价" align="center" prop="costPrice">
        <template slot-scope="scope">
          {{ toMoney(scope.row.costPrice) }}
        </template>
      </el-table-column>
      <el-table-column label="消耗数量" align="center" prop="consumeNumber" />
      <el-table-column label="消耗金额" align="center">
        <template slot-scope="scope">
          {{ toMoney(scope.row.consumeNumber * scope.row.costPrice) }}
        </template>
      </el-table-column>
      <el-table-column label="库存数量" align="center" prop="stockNumber" />
      <el-table-column label="库存金额" align="center" prop="stockMoney">
        <template slot-scope="scope">
          {{ toMoney(scope.row.stockMoney) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { commodityStatistics } from "@/api/cld/materialStatistics";
import { listErpCommodityType } from "@/api/erp/ErpCommodityType";
export default {
  name: "commodityStatistics",
  dicts: ["cld_project_region", "cld_project_business", "cld_project_duits"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null,
        staffName: null,
      },
      // 下拉商品类型
      options: [],
      defaultProps: {
        children: "children",
        label: "commodityTypeName",
      },
    };
  },
  created() {
    this.getList();
    // this.getListCommodityType();
  },
  methods: {
    getList() {
      commodityStatistics(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 获取商品类别 */
    getListCommodityType() {
      listErpCommodityType().then((response) => {
        this.options = this.handleTree(
          response.data,
          "commodityTypeId",
          "commodityTypePid"
        );
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
